<#macro displayDocument module document>
<div class="page-break">
	<h2 id="${module.name}-${document.name}" class="section-title">${module.name} - ${document.singularAlias}</h2>

	<#if document.documentation?? && document.documentation?has_content>
		<div class="documentation-container">
			<div class="documentation-description">${document.documentation!?no_esc}</div>
		</div>
	</#if>

	<#if document.diagram?? && document.diagram?has_content>
		<div class="center">
			<@plantUmlImage markup=document.diagram />
		</div>
	</#if>
	
	<#if document.attributes?? && document.attributes?has_content>
	<div class="page-break-avoid section">
		<h3 id="${document.name}-attributes">Attributes</h3>
		<p>The ${document.singularAlias} document contains the following attributes:</p>
		<table class="table attributes repeat-headings" id="${document.name}-attributes" style="width: 100%; table-layout: fixed;">
			<thead>
				<tr>
					<th style="width:17%;">Attribute Name</th>
					<th style="width:18%;">Display Name</th>
					<th style="width:13%;">Type</th>
					<th style="width:7%;">Size</th>
					<th style="width:9%;">Required</th>
					<th style="width:9%;">Persistent</th>
					<th style="width:16%;">Values</th>
					<th style="width:11%;">Deprecated</th>
				</tr>
			</thead>
			<tbody>
				<#assign rowColor1 = "white">
		        <#assign rowColor2 = "${defaultLightColor!}">
		        <#assign currentColor = rowColor1>
				<#list document.attributes as attribute>
					<#assign currentColor = (currentColor == rowColor1)?then(rowColor2, rowColor1)>
					<tr style="background-color: ${currentColor};">
			   			<td style="width: 17%;">${attribute.name}</td>
						<td style="width: 18%;">${attribute.displayName!}</td>
						<td style="width: 13%;">${attribute.type!}</td>
						<td style="width: 7%;">${attribute.size!}</td>
						<td style="width: 9%;">${attribute.required?c!}</td>
						<td style="width: 9%;">${attribute.persistent?c!}</td>
						<#if attribute.values?? && attribute.values?has_content>
							<td style="width: 16%;">
								<#list attribute.values as value>
									<li>${value!}</li>
								</#list>
							</td>
						<#else>
							<td style="width: 16%;"></td>
						</#if>
						<td style="width: 11%;">${attribute.deprecated?c!}</td>
			  		</tr>
				  	<#if attribute.description?has_content || attribute.documentation?has_content>
						<tr style="background-color: ${currentColor};">
							<td colspan="8" style="width: 100%;">
								<#if attribute.documentation?has_content>
								<div class="document-documentation">
									<div class="documentation-title">Documentation:</div>
									<div class="documentation-description">${attribute.documentation!?no_esc}</div>
								</div>
								</#if>
								<#if attribute.description?has_content>
								<div class="document-documentation">
									<div class="documentation-title">Description:</div>
									<div class="documentation-description">${attribute.description!?no_esc}</div>
								</div>
								</#if>
							</td>
						</tr>
					</#if>
				</#list>
			</tbody>
		</table>
	</div>
	</#if>

	<#if document.references?? && document.references?has_content>
	<div class="page-break-avoid section">
		<h3 id="${document.name}-references">References</h3>
		<p>The document ${document.singularAlias} contains the following references:</p>
		<table class="repeat-headings">
			<thead>
				<tr>
					<th>Reference</th>
					<th>Type</th>
					<th>Document</th>
					<th>Required</th>
					<th>Deprecated</th>
				</tr>
			</thead>
			<tbody>
				<#list document.references as reference>
				<tr>
					<td>${reference.name}</td>
					<td>${reference.type!}</td>
					<td>${reference.document!}</td>
					<td>${reference.required?c!}</td>
					<td>${reference.deprecated?c!}</td>
				</tr>
				</#list>
			</tbody>
		</table>
	</div>
	</#if>

	<#if document.conditions?? && document.conditions?has_content>
	<div class="page-break-avoid section">
		<h3 id="${document.name}-conditions">Conditions</h3>
		<p>The document ${document.singularAlias} contains the following conditions:</p>
		<table class="repeat-headings">
			<thead>
				<tr>
					<th>Name</th>
					<th>Documentation</th>
				</tr>
			</thead>
			<tbody>
				<#list document.conditions as condition>
				<tr>
					<td>${condition.name}</td>
					<td>${condition.documentation!?no_esc}</td>
				</tr>
				</#list>
			</tbody>
		</table>
	</div>
	</#if>

	<#if document.constraints?? && document.constraints?has_content>
	<div class="page-break-avoid section">
		<h3 id="${document.name}-constraints">Unique Constraints</h3>
		<p>The document ${document.singularAlias} contains the following
			constraints:</p>
		<table class="repeat-headings">
			<thead>
				<tr>
					<th>Constraint</th>
					<th>Description</th>
					<th>Scope</th>
					<th>References</th>
				</tr>
			</thead>
			<tbody>
				<#list document.constraints as constraint>
				<tr>
					<td>${constraint.name}</td>
					<td>${constraint.description!?no_esc}</td>
					<td>${constraint.scope!}</td>
					<td>${constraint.references!}</td>
				</tr>
				</#list>
			</tbody>
		</table>
	</div>
	</#if>

	<#if document.actions?? && document.actions?has_content>
	<div class="page-break-avoid section">
		<h3 id="${document.name}-actions">Actions</h3>
		<p>The document ${document.singularAlias} contains the following actions:</p>
		<ul>
			<#list document.actions as action>
			<li>${action.name}</li>
			</#list>
		</ul>
	</div>
	</#if>
</div>
</#macro>

<#macro displayModule module>
<div>
	<div>
		<h1 id="${module.name}" class="module-header">${module.name} module</h1>
	</div>


	<#if module.queries?? && module.queries?has_content>
	<h3 class="module-header" id="${module.name}-queries">Queries</h3>
	<p>The ${module.name} module contains the following queries:</p>
	<table style="margin-bottom : 50px;" class="page-break-avoid repeat-headings">
		<thead>
			<tr>
				<th>Query</th>
				<th>Driving Document</th>
				<th>Description</th>
				<th>Documentation</th>
			</tr>
		</thead>
		<tbody>
			<#assign row_index=0> <#list module.queries as query>
			<tr>
				<td>${query.name}</td>
				<td>${query.drivingDocument!}</td>
				<td>${query.description!?no_esc}</td>
				<td>${query.documentation!?no_esc}</td>
			</tr>
			<#assign row_index=row_index+1>
		        </#list>
		</tbody>
	</table>
	</#if>

	<#if module.roles?? && module.roles?has_content>
	<h3 class="module-header" id="${module.name}-roles">Roles</h3>
	<p>The ${module.name} module contains the following roles:</p>
	<table style="margin-bottom : 50px;" class="page-break-avoid repeat-headings">
		<thead>
			<tr>
				<th>Role</th>
				<th>Description</th>
				<th>Documentation</th>
			</tr>
		</thead>
		<tbody>
			<#assign row_index=0> <#list module.roles as role>
			<tr>
				<td>${role.name}</td>
				<td>${role.descrption!}</td>
				<td>${role.documentation!?no_esc}</td>
			</tr>
			<#assign row_index=row_index+1>
		        </#list>
		</tbody>
	</table>
	</#if>

	<#if module.jobs?? && module.jobs?has_content>
	<h3 class="module-header" id="${module.name}-jobs">Jobs</h3>
	<p>The ${module.name} module contains the following jobs:</p>
	<table style="margin-bottom : 50px;" class="page-break-avoid repeat-headings">
		<thead>
			<tr>
				<th>Name</th>
				<th>Job</th>
				<th>Class</th>
			</tr>
		</thead>
		<tbody>
			<#assign row_index=0>
			<#list module.jobs as job>
			<tr>
				<td>${job.name}</td>
				<td>${job.displayName!}</td>
				<td>${job.className!}</td>
			</tr>
			<#assign row_index=row_index+1>
		        </#list>
		</tbody>
	</table>
	</#if>

	<h3 class="module-header" id="${module.name}-documents">Documents</h3>
	<p>The ${module.name} module contains the following documents:</p>
	<table style="margin-bottom : 50px;" class="page-break-avoid repeat-headings page-break">
		<thead>
			<tr>
				<th>Document Name</th>
				<th>Documentation</th>
			</tr>
		</thead>
		<tbody>
			<#assign row_index=0> <#list module.documents as doc>
			<tr>
				<td>${doc.name}</td>
				<td>${doc.documentation!?no_esc}</td>
			</tr>
			<#assign row_index=row_index+1>
	        </#list>
		</tbody>
	</table>

	<#list module.documents as document> <@displayDocument module document /> </#list>
	
</div>
</#macro>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>${title}</title>
<#include "/reportBaseStyles.ftlh">
<#assign modules=data.modules>
<style>

@page {
        size: A4 portrait;
         @bottom-center{
         	content: "Version: ${pomVersion}";
            font-family: 'SourceSansPro', 'Arial', 'Microsoft Sans Serif', sans-serif;
            font-size: 10px;
            color: #333333;
         }
}
@page:first {
  @bottom-left {
  	content: normal;
  }
  @bottom-center {
  	content: normal;
  }
  @bottom-right {
  	content: normal;
  }
}
body {
	font-family: Arial, sans-serif;
	font-size: 12px;
}

table {
	border-collapse: collapse;
	border-spacing: 0;
}

  table.attributes th, table.attributes td {
    word-wrap: break-word;
    white-space: normal;
    font-size: 10px;
  }

h1 {
	font-size: 24px;
	color: ${defaultDarkColor!};
}

h2 {
	font-size: 20px;
}

h3 {
	font-size: 14px;
}

.document-documentation {
	padding-bottom: 5px;
}

.documentation-title {
	display: table-cell;
	font-weight: bold;
	color: #333;
	width: 100px;
	vertical-align: top;
	padding-right: 10px;
}

.documentation-description {
	display: table-cell;
	color: #555;
	text-align: justify;
}

thead {
	background-color: ${defaultColor!};
}

tbody > tr:nth-child(even) {
    background-color: ${defaultLightColor!};
}

thead th.title {
	text-align: center;
}

td, th {
	padding-left: 5px;
	max-width: 50px;
}

.module-header {
	padding: 10px;
	text-align: center;
	text-decoration: underline;
	color: ${defaultDarkColor!};
}

h3.module-header{
	text-align: left;
	text-decoration: none ;
	padding : 0;
	margin-top: 10px;
}

.section{
	margin-bottom : 50px;
}

.section-title {
	color: ${defaultDarkColor!};
	text-align:center;
	padding:5px;
	font-weight : bold;
}

.toc li>a {
	text-decoration: inherit;
	color: inherit;
	font-family: inherit;
}

.toc h1 {
	margin-bottom: 20px;
	text-align: center;
	font-size: 28px;
}

.toc-section-contents>ol>li{
	font-size: 18px;
}

.toc-section-contents>ol>li>ol>li{
	font-size: 14px;
}

.toc-section-contents-documents>ol>li {
	list-style-position: inside;
	font-size: 14px;
}

.toc-section-contents-documents>ol>li>a {
	background-color: ${defaultColor!};
	list-style-position: inside;
	display:inline-block;
	margin-bottom: 10px;
	padding-left:5px;
	color:white;
	width:90%;
}

.toc-section-contents-documents ol>li>ol>li {
	font-size: 12px;
	margin-bottom: 10px;
	width:95%;
	border-bottom: 1px dotted ${defaultColor!};
}

.toc-section-contents>ol>li>a{
	color: ${defaultColor!};
}

.toc ol { counter-reset: item }
.toc li{ display: block }
.toc-section-contents>ol>li:before { content: counters(item, ".") ". "; counter-increment: item }
.toc li:before { content: counters(item, ".") " "; counter-increment: item }

</style>
</head>
<body>

	<#-- Title Page -->
	<div style="page-break-after: always; width: 100%; height: 100%; padding-top:300px; text-align: center; font-family: Arial, sans-serif;">
	    <table style="width: 100%; height: 100%;  border: none; margin: 0; padding: 0;">
	        <tr>
	            <td style="vertical-align: middle; text-align: center;">
					<img src="data:image/png;base64,${logo}" alt="Skyve Logo" height="40" />
	                <h1 style="font-size: 36px; margin-bottom: 10px;">${projectName}</h1>
	                <h2 style="font-size: 24px; color: gray;">System Documentation Report</h2>
	                <p style="font-size: 18px; margin-top: 40px;">Generated on: ${.now}</p>
	            </td>
	        </tr>
	    </table>
	</div>


	<header>
		<div class="logo">
			<img src="data:image/png;base64,${logo}" alt="Skyve Logo" height="30" />
		</div>
		<div class="company">
			<h2 class="name" style="font-size: 18px;">${title}</h2>
		</div>
	</header>
	<div class="toc" style="-fs-page-sequence: start;">
		<h1>Table of Contents</h1>
		<div class="toc-section">
			<div class="toc-section-contents">
				<ol>
					<#list modules as module>
					<li><a class="toc-module-title" href="#${module.name}">${module.name} module</a>
						<ol style="list-style-type: disc;">
							<#if module.queries?? && module.queries?has_content>
							<li><a class="toc-module-attribute"
								href="#${module.name}-queries">Queries</a></li>
							</#if>

							<#if module.roles?? && module.roles?has_content>
							<li><a class="toc-module-attribute" href="#${module.name}-roles">Roles</a></li>
							</#if>

							<#if module.jobs?? && module.jobs?has_content>
							<li><a class="toc-module-attribute" href="#${module.name}-jobs">Jobs</a></li>
							</#if>

							<#if module.documents?? && module.documents?has_content>
							<li><a class="toc-module-attribute" href="#${module.name}-documents">Documents</a>
								<div class="toc-section-contents-documents"
									style="page-break-after: always">
									<ol>
										<#list module.documents as document>
										<li><a class="toc-document-title"
											href="#${module.name}-${document.name}">${document.singularAlias}</a>
											<ol>
												<#if
													document.attributes?? && document.attributes?has_content>
												<li><a class="toc-document-attribute"
													href="#${document.name}-attributes">Attributes</a></li>
												</#if>
												<#if
													document.references?? && document.references?has_content>
												<li><a class="toc-document-attribute"
													href="#${document.name}-references">References</a></li>
												</#if>
												<#if
													document.conditions?? && document.conditions?has_content>
												<li><a class="toc-document-attribute"
													href="#${document.name}-conditions">Conditions</a></li>
												</#if>
												<#if
													document.constraints?? && document.constraints?has_content>
												<li><a class="toc-document-attribute"
													href="#${document.name}-constraints">Constraints</a></li>
												</#if>
												<#if document.actions?? && document.actions?has_content>
												<li><a class="toc-document-attribute"
													href="#${document.name}-actions">Actions</a></li>
												</#if>
											</ol></li>
										</#list>
									</ol>
								</div></li>
							</#if>
						</ol></li>
					</#list>
				</ol>
			</div>
		</div>

	</div>

	<#list modules as module> <@displayModule module /> </#list>
</body>
</html>